package org.file5.service.impl;

import java.util.Date;

import org.apache.log4j.Logger;
import org.file5.dao.DaoFascade;
import org.file5.domain.BaseEntity.STATUS;
import org.file5.domain.EntityComment;
import org.file5.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("commentService")
public class CommentServiceImpl implements CommentService {

	private final Logger logger = Logger.getLogger(this.getClass());
	@Autowired
	DaoFascade df;

	@Override
	public void delete(String uid) {
		EntityComment comment = df.getBaseDao().find(EntityComment.class, uid);
		if (comment != null) {
			//TODO: remove its sub replies

			df.getBaseDao().remove(comment);
		}

	}
 
	@Override
	public EntityComment updateStatus(String uid, STATUS status) {
		EntityComment comment = df.getBaseDao().find(EntityComment.class, uid);
		if (comment != null) {

			comment.setStatus(status);
			comment.setStatusUpdated(new Date());
			df.getBaseDao().addUpdate(comment);
		}
		return comment;
	}
 
}
